package com.danbay.cloud.lock.device.util;

import com.google.common.collect.Lists;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * @author yangyanchen on 2017/12/19
 *         Copyright © 2016 －2017 旦倍科技
 */
public class CollectionUtils {

    public static List<Map<String, String>> getMapDiff(List<Map<String, String>> collmax, List<Map<String, String>> collmin, String mapKey) {
        List<Map<String, String>> csReturn = Lists.newLinkedList();
        List<Map<String, String>> max = collmax;
        List<Map<String, String>> min = collmin;
        if(collmax.size() < collmin.size()) {
            max = collmin;
            min = collmax;
        }

        Map<Object, Integer> map = new HashMap(max.size());

        Map object;
        for(int i = 0; i < max.size(); ++i) {
            object = (Map)max.get(i);
            map.putIfAbsent(object.get(mapKey), Integer.valueOf(i));
        }

        Iterator var9 = min.iterator();

        while(var9.hasNext()) {
            object = (Map)var9.next();
            if(map.get(object.get(mapKey)) == null) {
                csReturn.add(object);
            } else {
                map.put(object.get(mapKey), Integer.valueOf(-1));
            }
        }

        var9 = map.entrySet().iterator();

        while(var9.hasNext()) {
            Map.Entry<Object, Integer> entry = (Map.Entry)var9.next();
            if(((Integer)entry.getValue()).intValue() != -1) {
                csReturn.add(max.get(((Integer)entry.getValue()).intValue()));
            }
        }

        return csReturn;
    }
}
